package geometrie;

/**
 * 
 * Class that represents a point in the 3D scene. The points are here
 * represented by its Cartesian coordinates (x, y, z). It's also responsible for
 * the operations of transformation applied in a point.
 * 
 */
public class Point {
	// Cartesian coordinates
	private double x;
	private double y;
	private double z;

	/**
	 * Get the x coordinate of this point
	 * 
	 * @return x the coordinate x of the point
	 */
	public double getXCartesien() {
		return this.x;
	}

	/**
	 * Get the Y coordinate of this point
	 * 
	 * @return y The coordinate y of the point
	 */
	public double getYCartesien() {
		return this.y;
	}

	/**
	 * Get the Z coordinate of this point
	 * 
	 * @return z The coordinate z of the point
	 */
	public double getZCartesien() {
		return this.z;
	}

	/**
	 * Method to the change the coordinates of this point
	 * 
	 * @param x
	 *            the x coordinate
	 * @param y
	 *            the y coordinate
	 * @param z
	 *            the z coordinate
	 */
	public void set(double x, double y, double z) {
		this.x = x;
		this.z = z;
		this.y = y;
	}

	/**
	 * Constructs a point from its x, y and z coordinates.
	 * 
	 * @param x
	 *            the x coordinate
	 * @param y
	 *            the y coordinate
	 * @param z
	 *            the z coordinate
	 */
	public Point(double x, double y, double z) {
		this.x = x;
		this.z = z;
		this.y = y;
	}

	/**
	 * Method that add a given quantity in each coordinate of this point
	 * 
	 * @param qtX
	 *            the quantity to sum in the X coordinate
	 * @param qtY
	 *            the quantity to sum in the Y coordinate
	 * @param qtZ
	 *            the quantity to sum in the Z coordinate
	 * @return A new point in which these quantities are summed
	 */
	public Point add(double qtX, double qtY, double qtZ) {
		return new Point(x + qtX, y + qtY, z + qtZ);
	}

	/**
	 * Method responsible to apply the transformation in this point
	 * 
	 * @param t
	 */
	public void applyTransformation(Transformation t) {
		double[][] newPoint = new double[4][1];
		newPoint[0][0] = x;
		newPoint[1][0] = y;
		newPoint[2][0] = z;
		newPoint[3][0] = 1;
		newPoint = Transformation.matrixMultiplication(t.getMatrix(), newPoint,
				4, 4, 4, 1);
		x = newPoint[0][0] / newPoint[3][0];
		y = newPoint[1][0] / newPoint[3][0];
		z = newPoint[2][0] / newPoint[3][0];
	}

	@Override
	public String toString() {
		return "Point [x=" + x + ", y=" + y + ", z=" + z + "]";
	}

}
